Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Collections.​Generic.​HashSet<​T>

Assembly: System.Collections

Inheritance: object → HashSet

Implemented Interfaces

Represents a set of values.

Properties

public IEqualityComparer<​T>
Comparer
Gets the <see cref="T:System.Collections.Generic.IEqualityComparer`1" /> object that is used to determine equality for the values in the set.
public int
Count
Gets the number of elements that are contained in a set.
public int
Capacity
Gets the total numbers of elements the internal data structure can hold without resizing.

Methods

public bool
Add​(T item)
Adds the specified element to a set.
Returns <see langword="true" /> if the element is added to the <see cref="T:System.Collections.Generic.HashSet`1" /> object; <see langword="false" /> if the element is already present.
item The element to add to the set.
public void
Clear​()
Removes all elements from a <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public bool
Contains​(T item)
Determines whether a <see cref="T:System.Collections.Generic.HashSet`1" /> object contains the specified element.
Returns <see langword="true" /> if the <see cref="T:System.Collections.Generic.HashSet`1" /> object contains the specified element; otherwise, <see langword="false" /> .
item The element to locate in the <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public void
CopyTo​(T[] array)
Copies the elements of a <see cref="T:System.Collections.Generic.HashSet`1" /> object to an array.
array The one-dimensional array that is the destination of the elements copied from the <see cref="T:System.Collections.Generic.HashSet`1" /> object. The array must have zero-based indexing.
public void
CopyTo​(T[] array, int arrayIndex)
Copies the elements of a <see cref="T:System.Collections.Generic.HashSet`1" /> object to an array, starting at the specified array index.
array The one-dimensional array that is the destination of the elements copied from the <see cref="T:System.Collections.Generic.HashSet`1" /> object. The array must have zero-based indexing.
arrayIndex The zero-based index in <paramref name="array" /> at which copying begins.
public void
CopyTo​(T[] array, int arrayIndex, int count)
Copies the specified number of elements of a <see cref="T:System.Collections.Generic.HashSet`1" /> object to an array, starting at the specified array index.
array The one-dimensional array that is the destination of the elements copied from the <see cref="T:System.Collections.Generic.HashSet`1" /> object. The array must have zero-based indexing.
arrayIndex The zero-based index in <paramref name="array" /> at which copying begins.
count The number of elements to copy to <paramref name="array" /> .
public static IEqualityComparer<​HashSet<​T>>
CreateSetComparer​()
Returns an <see cref="T:System.Collections.IEqualityComparer" /> object that can be used for equality testing of a <see cref="T:System.Collections.Generic.HashSet`1" /> object.
Returns An <see cref="T:System.Collections.IEqualityComparer" /> object that can be used for deep equality testing of the <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public int
EnsureCapacity​(int capacity)
Ensures that this hash set can hold the specified number of elements without any further expansion of its backing storage.
Returns The new capacity of this instance.
capacity The minimum capacity to ensure.
public void
ExceptWith​(IEnumerable<​T> other)
Removes all elements in the specified collection from the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
other The collection of items to remove from the <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public AlternateLookup<​T, TAlternate>
GetAlternateLookup​()
Gets an instance of a type that can be used to perform operations on the current <see cref="T:System.Collections.Generic.HashSet`1" /> using a <typeparamref name="TAlternate" /> instead of a <typeparamref name="T" /> .
Returns The created lookup instance.
public Enumerator<​T>
GetEnumerator​()
Returns an enumerator that iterates through a <see cref="T:System.Collections.Generic.HashSet`1" /> object.
Returns A <see cref="T:System.Collections.Generic.HashSet`1.Enumerator" /> object for the <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public void
GetObjectData​(Runtime.​Serialization.​SerializationInfo info, Runtime.​Serialization.​StreamingContext context)
Implements the <see cref="T:System.Runtime.Serialization.ISerializable" /> interface and returns the data needed to serialize a <see cref="T:System.Collections.Generic.HashSet`1" /> object.
info A <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object that contains the information required to serialize the <see cref="T:System.Collections.Generic.HashSet`1" /> object.
context A <see cref="T:System.Runtime.Serialization.StreamingContext" /> structure that contains the source and destination of the serialized stream associated with the <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public void
IntersectWith​(IEnumerable<​T> other)
Modifies the current <see cref="T:System.Collections.Generic.HashSet`1" /> object to contain only elements that are present in that object and in the specified collection.
other The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public bool
IsProperSubsetOf​(IEnumerable<​T> other)
Determines whether a <see cref="T:System.Collections.Generic.HashSet`1" /> object is a proper subset of the specified collection.
Returns <see langword="true" /> if the <see cref="T:System.Collections.Generic.HashSet`1" /> object is a proper subset of <paramref name="other" /> ; otherwise, <see langword="false" /> .
other The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public bool
IsProperSupersetOf​(IEnumerable<​T> other)
Determines whether a <see cref="T:System.Collections.Generic.HashSet`1" /> object is a proper superset of the specified collection.
Returns <see langword="true" /> if the <see cref="T:System.Collections.Generic.HashSet`1" /> object is a proper superset of <paramref name="other" /> ; otherwise, <see langword="false" /> .
other The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public bool
IsSubsetOf​(IEnumerable<​T> other)
Determines whether a <see cref="T:System.Collections.Generic.HashSet`1" /> object is a subset of the specified collection.
Returns <see langword="true" /> if the <see cref="T:System.Collections.Generic.HashSet`1" /> object is a subset of <paramref name="other" /> ; otherwise, <see langword="false" /> .
other The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public bool
IsSupersetOf​(IEnumerable<​T> other)
Determines whether a <see cref="T:System.Collections.Generic.HashSet`1" /> object is a superset of the specified collection.
Returns <see langword="true" /> if the <see cref="T:System.Collections.Generic.HashSet`1" /> object is a superset of <paramref name="other" /> ; otherwise, <see langword="false" /> .
other The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public void
OnDeserialization​(object sender)
Implements the <see cref="T:System.Runtime.Serialization.ISerializable" /> interface and raises the deserialization event when the deserialization is complete.
sender The source of the deserialization event.
public bool
Overlaps​(IEnumerable<​T> other)
Determines whether the current <see cref="T:System.Collections.Generic.HashSet`1" /> object and a specified collection share common elements.
Returns <see langword="true" /> if the <see cref="T:System.Collections.Generic.HashSet`1" /> object and <paramref name="other" /> share at least one common element; otherwise, <see langword="false" /> .
other The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public bool
Remove​(T item)
Removes the specified element from a <see cref="T:System.Collections.Generic.HashSet`1" /> object.
Returns <see langword="true" /> if the element is successfully found and removed; otherwise, <see langword="false" /> . This method returns <see langword="false" /> if <paramref name="item" /> is not found in the <see cref="T:System.Collections.Generic.HashSet`1" /> object.
item The element to remove.
public int
RemoveWhere​(Predicate<​T> match)
Removes all elements that match the conditions defined by the specified predicate from a <see cref="T:System.Collections.Generic.HashSet`1" /> collection.
Returns The number of elements that were removed from the <see cref="T:System.Collections.Generic.HashSet`1" /> collection.
match The <see cref="T:System.Predicate`1" /> delegate that defines the conditions of the elements to remove.
public bool
SetEquals​(IEnumerable<​T> other)
Determines whether a <see cref="T:System.Collections.Generic.HashSet`1" /> object and the specified collection contain the same elements.
Returns <see langword="true" /> if the <see cref="T:System.Collections.Generic.HashSet`1" /> object is equal to <paramref name="other" /> ; otherwise, <see langword="false" /> .
other The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public void
SymmetricExceptWith​(IEnumerable<​T> other)
Modifies the current <see cref="T:System.Collections.Generic.HashSet`1" /> object to contain only elements that are present either in that object or in the specified collection, but not both.
other The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public void
TrimExcess​()
Sets the capacity of a <see cref="T:System.Collections.Generic.HashSet`1" /> object to the actual number of elements it contains, rounded up to a nearby, implementation-specific value.
public void
TrimExcess​(int capacity)
Sets the capacity of a <see cref="T:System.Collections.Generic.HashSet`1" /> object to the specified number of entries, rounded up to a nearby, implementation-specific value.
capacity The new capacity.
public bool
TryGetAlternateLookup​(AlternateLookup`1& lookup)
public bool
TryGetValue​(T equalValue, T& actualValue)
public void
UnionWith​(IEnumerable<​T> other)
Modifies the current <see cref="T:System.Collections.Generic.HashSet`1" /> object to contain all elements that are present in itself, the specified collection, or both.
other The collection to compare to the current <see cref="T:System.Collections.Generic.HashSet`1" /> object.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object